package tech.ezrealc.fall2023.controller.affair;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import tech.ezrealc.fall2023.model.affair.classe.ClasseVO;
import tech.ezrealc.fall2023.model.affair.classe.mapper.ClasseMapper;
import tech.ezrealc.fall2023.model.common.ResponseModel;
import tech.ezrealc.fall2023.service.affair.classe.ClasseService;

import java.math.BigInteger;

@RestController
@RequestMapping("/api/affair/classe")
@CrossOrigin
public class ClasseController {

    @Resource
    private ClasseService classeService;
    @Resource
    private ClasseMapper classeMapper;

    @GetMapping
    public ResponseModel query() {
        return ResponseModel.success(classeMapper.toVOList(classeService.queryAllRecords()));
    }

    @PostMapping
    public ResponseModel add(@RequestBody ClasseVO classeVO) {
        classeService.addRecord(classeMapper.toDTO(classeVO));
        return ResponseModel.success("新增成功");
    }

    @DeleteMapping
    public ResponseModel remove(@RequestParam("id")BigInteger id){
        classeService.deleteRecord(id);
        return ResponseModel.success("删除成功");
    }

    @PutMapping
    public ResponseModel edit(@RequestBody ClasseVO classeVO){
        classeService.modifyRecord(classeMapper.toDTO(classeVO));
        return ResponseModel.success("修改成功");
    }

}
